#include <touchgfx/hal/OSWrappers.hpp>
using namespace touchgfx;

static volatile uint32_t fb_sem;
static volatile uint32_t vsync_sem;

void OSWrappers::initialize()
{
  fb_sem = 0;
  vsync_sem = 0;
}

void OSWrappers::takeFrameBufferSemaphore()
{
  while(fb_sem);
  fb_sem = 1;
}
void OSWrappers::giveFrameBufferSemaphore()
{
  fb_sem = 0;
}

void OSWrappers::tryTakeFrameBufferSemaphore()
{
  fb_sem = 1;
}

void OSWrappers::giveFrameBufferSemaphoreFromISR()
{
  fb_sem = 0;
}

void OSWrappers::signalVSync()
{
  vsync_sem = 1;
}

void OSWrappers::waitForVSync()
{
  vsync_sem = 0;
  while(!vsync_sem);
}